<?php
/**
 * 管理内容
 */

class Content_ManageController extends Cms_AdminController {
	/**
	 * 初始化
	 */
	public function init() {
		parent::init ();
	}
	
	public function indexAction() {
		$this->render ( 'Content/manage/index', null, true );
	}
	
	/**
	 * 内容管理
	 */
	public function listAction() {
		$this->view->setScriptFile ( 'admin/admin_common.js' );
		$this->view->setScriptFile ( 'cookie.js' );
		
		$this->view->setScriptFile ( 'admin/calendar/calendar.js' );
		$this->view->setScriptFile ( 'admin/calendar/lang/en.js' );
		
		$this->view->setCssFile ( 'calendar/jscal2.css' );
		$this->view->setCssFile ( 'calendar/border-radius.css' );
		$this->view->setCssFile ( 'calendar/win2k.css' );
		
		$id = $this->_request->get ( 'id' );
		
		$this->view->assign ( 'id', $id );
		
		$DB_News = new DB_News ();
		$where = "catid={$id}";
		
		$Page = new Cms_Pager ( $DB_News );
		
		// 设置Ajax分页
		// $Page = new Cms_Pager ( $DB_News, 'page', 'ajax' );
		// $Page->setAjaxFun ('ContentPage',"/content/manage/ajaxlist/id/{$id}/"
		// );
		
		$Pagelimit = $Page->loadPagerData ( 10, $where );
		
		$News_list = $DB_News->loadList ( '*', $where, "id DESC", $Pagelimit );
		
		if ($News_list) {
			foreach ( $News_list as $key => $val ) {
				if ($val ['style']) {
					$style = explode ( ';', $val ['style'] );
					$News_list [$key] ['style'] = '';
					if (! empty ( $style [0] ) && strstr ( $style [0], '#' )) {
						$News_list [$key] ['style'] .= "color:{$style[0]};";
					}
					if (! empty ( $style [0] ) && strstr ( $style [0], 'bold' )) {
						$News_list [$key] ['style'] .= "font-weight:{$style[0]};";
					}
					if (! empty ( $style [1] ) && strstr ( $style [1], '#' )) {
						$News_list [$key] ['style'] .= "color:{$style[1]};";
					}
					if (! empty ( $style [1] ) && strstr ( $style [1], 'bold' )) {
						$News_list [$key] ['style'] .= "font-weight:{$style[1]};";
					}
				}
				$News_list [$key] ['updatetime'] = date ( "Y-m-d H:i:s", $val ['updatetime'] );
			}
		}
		
		$this->view->assign ( "pageBlock", $Page->loadPagerTpl () );
		$this->view->assign ( 'News_list', $News_list );
		$this->render ( 'Content/manage/list', null, true );
	}
	
	/**
	 * 内容列表 Ajax取内容
	 */
	public function ajaxlistAction() {
		// dump($this->_request);exit;
		$id = $this->_request->get ( 'id' );
		$page = $this->_request->getPost ( 'page' );
		
		$DB_News = new DB_News ();
		$where = "catid={$id}";
		$Page = new Cms_Pager ( $DB_News, 'page', 'Ajax' );
		$Page->currentPage = $page;
		$Page->setAjaxFun ( 'ContentPage', "/content/manage/ajaxlist/id/{$id}/" );
		$Pagelimit = $Page->loadPagerData ( 1, $where );
		
		$News_list = $DB_News->loadList ( '*', $where, null, $Pagelimit );
		
		if ($News_list) {
			foreach ( $News_list as $key => $val ) {
				if ($val ['style']) {
					$style = explode ( ';', $val ['style'] );
					$News_list [$key] ['style'] = '';
					if (! empty ( $style [0] ) && strstr ( $style [0], '#' )) {
						$News_list [$key] ['style'] .= "color:{$style[0]};";
					}
					if (! empty ( $style [0] ) && strstr ( $style [0], 'bold' )) {
						$News_list [$key] ['style'] .= "font-weight:{$style[0]};";
					}
					if (! empty ( $style [1] ) && strstr ( $style [1], '#' )) {
						$News_list [$key] ['style'] .= "color:{$style[1]};";
					}
					if (! empty ( $style [1] ) && strstr ( $style [1], 'bold' )) {
						$News_list [$key] ['style'] .= "font-weight:{$style[1]};";
					}
				}
				$News_list [$key] ['updatetime'] = date ( "Y-m-d H:i:s", $val ['updatetime'] );
			}
		}
		
		$this->view->assign ( "pageBlock", $Page->loadPagerTpl () );
		$this->view->assign ( 'News_list', $News_list );
		$this->render ( 'Content/manage/listcontent', null, true );
	}
	
	/**
	 * 添加内容
	 */
	public function addAction() {
		
		$dosubmit = $this->_request->getPost ( 'dosubmit' );
		$dosubmit_continue = $this->_request->getPost ( 'dosubmit_continue' );
		
		if (isset ( $dosubmit ) || isset ( $dosubmit_continue )) {
			$info = $this->_request->getPost ( 'info' );
			// dump ( $_POST );
			// exit ();
			
			$style = '';
			if (! empty ( $info ['style_color'] )) {
				$style = $info ['style_color'];
			}
			if (! empty ( $info ['style_font_weight'] )) {
				$style .= ';' . $info ['style_font_weight'];
			}
			
			if (! empty ( $info ['createtime'] )) {
				$createtime = strtotime ( $info ['createtime'] );
			} else {
				$createtime = time ();
			}
			$news_info = array (
					'catid' => $info ['catid'],
					'title' => $info ['title'],
					'style' => $style,
					'news_img' => '',
					'keywords' => $info ['keywords'],
					'description' => $info ['description'],
					'istop' => $info ['istop'],
					'username' => $this->AdminSessionInfo ['username'],
					'createtime' => $createtime,
					'updatetime' => time () 
			);
			$Model_News = new Model_News ();
			$return_id = $Model_News->add_News ( $news_info );
			if ($return_id > 0) {
				$news_data = array (
						'id' => $return_id,
						'content' => $info ['content'],
						'pagetype' => $info ['pagetype'],
						'maxcharperpage' => $info ['maxcharperpage'],
						'relation' => $info ['relation'],
						'allow_comment' => $info ['allow_comment'],
						'copyfrom' => $info ['copyfrom'] 
				);
				$Model_NewsData = new Model_NewsData ();
				if ($Model_NewsData->add_News ( $news_data )) {
					// 上传图片
					if (! empty ( $info ['news_img'] )) {
						$config = Zend_Registry::get ( 'config' );
						$Upload_Content = new Model_UploadFile ( $return_id, 'content', 'local' );
						$Upload_Content->uploadContent ( str_replace ( $config->view_conf->siteUploadPath, UPLOAD_PATH, $info ['news_img'] ) );
					}
					if ($dosubmit) {
						$this->view->perRedirect ( '添加内容成功！', 'blank', '', '', '1' );
					} else {
						$this->view->perRedirect ( '添加内容成功！', "/content/manage/add/id/{$info['catid']}/" );
					}
				} else {
					$this->view->perRedirect ( '添加内容失败！', "/content/manage/add/id/{$info['catid']}/" );
				}
			} else {
				$this->view->perRedirect ( '添加内容失败！', "/content/manage/add/id/{$info['catid']}/" );
			}
		} else {
			$this->view->setScriptFile ( 'admin/admin_common.js' );
			$this->view->setScriptFile ( 'cookie.js' );
			
			$this->view->setScriptFile ( 'admin/content_addtop.js' );
			$this->view->setScriptFile ( 'admin/colorpicker.js' );
			
			$this->view->setScriptFile ( 'admin/calendar/calendar.js' );
			$this->view->setScriptFile ( 'admin/calendar/lang/en.js' );
			$this->view->setScriptFile ( 'ckeditor/ckeditor.js' );
			$this->view->setScriptFile ( 'formvalidator.js' );
			$this->view->setScriptFile ( 'formvalidatorregex.js' );
			
			$this->view->setCssFile ( 'calendar/jscal2.css' );
			$this->view->setCssFile ( 'calendar/border-radius.css' );
			$this->view->setCssFile ( 'calendar/win2k.css' );
			
			$id = $this->_request->get ( 'id' );
			$DB_Category = new DB_Category ();
			$DB_Category_info = $DB_Category->loadInfoByPrimary ( $id );
			
			$DB_Copyfrom = new DB_Copyfrom ();
			$Copyfrom_list = $DB_Copyfrom->loadList ( '*', "", "listorder ASC,id DESC" );
			$this->view->assign ( 'Copyfrom_list', $Copyfrom_list );
			
			$this->view->assign ( 'id', $id );
			$this->view->assign ( 'catname', $DB_Category_info ['catname'] );
			$this->view->assign ( 'taday', date ( "Y-m-d H:i:s", time () ) );
			
			$this->render ( 'Content/manage/add', null, true );
		}
	}
	
	/**
	 * 编辑内容
	 */
	public function editAction() {
		$dosubmit = $this->_request->getPost ( 'dosubmit' );
		$dosubmit_continue = $this->_request->getPost ( 'dosubmit_continue' );
		
		if (isset ( $dosubmit ) || isset ( $dosubmit_continue )) {
			$id = $this->_request->getPost ( 'id' );
			$info = $this->_request->getPost ( 'info' );
			// dump ( $_POST );
			// exit ();
			
			$style = '';
			if (! empty ( $info ['style_color'] )) {
				$style = $info ['style_color'];
			}
			if (! empty ( $info ['style_font_weight'] )) {
				$style .= ';' . $info ['style_font_weight'];
			}
			
			if (! empty ( $info ['createtime'] )) {
				$createtime = strtotime ( $info ['createtime'] );
			} else {
				$createtime = time ();
			}
			$news_info = array (
					'catid' => $info ['catid'],
					'title' => $info ['title'],
					'style' => $style,
					'keywords' => $info ['keywords'],
					'description' => $info ['description'],
					'istop' => $info ['istop'],
					'username' => $this->AdminSessionInfo ['username'],
					'createtime' => $createtime,
					'updatetime' => time () 
			);
			$Model_News = new Model_News ();
			$return = $Model_News->edit_News ( $id, $news_info );
			if ($return) {
				$news_data = array (
						'content' => $info ['content'],
						'pagetype' => $info ['pagetype'],
						'maxcharperpage' => $info ['maxcharperpage'],
						'relation' => $info ['relation'],
						'allow_comment' => $info ['allow_comment'],
						'copyfrom' => $info ['copyfrom'] 
				);
				$Model_NewsData = new Model_NewsData ();
				if ($Model_NewsData->edit_News ( $id, $news_data )) {
					// 上传图片
					if (! empty ( $info ['news_img'] )) {
						$config = Zend_Registry::get ( 'config' );
						$Upload_Content = new Model_UploadFile ( $id, 'content', 'local' );
						$Upload_Content->uploadContent ( str_replace ( $config->view_conf->siteUploadPath, UPLOAD_PATH, $info ['news_img'] ) );
					}
					if ($dosubmit) {
						$this->view->perRedirect ( '编辑内容成功！', 'blank', '', '', '1' );
					} else {
						$this->view->perRedirect ( '编辑内容成功！', "/content/manage/edit/catid/{$info['catid']}/id/{$id}/" );
					}
				} else {
					$this->view->perRedirect ( '编辑内容失败！', "/content/manage/edit/catid/{$info['catid']}/id/{$id}/" );
				}
			} else {
				$this->view->perRedirect ( '编辑内容失败！', "/content/manage/edit/catid/{$info['catid']}/id/{$id}/" );
			}
		} else {
			$this->view->setScriptFile ( 'admin/admin_common.js' );
			$this->view->setScriptFile ( 'cookie.js' );
			
			$this->view->setScriptFile ( 'admin/content_addtop.js' );
			$this->view->setScriptFile ( 'admin/colorpicker.js' );
			
			$this->view->setScriptFile ( 'admin/calendar/calendar.js' );
			$this->view->setScriptFile ( 'admin/calendar/lang/en.js' );
			$this->view->setScriptFile ( 'ckeditor/ckeditor.js' );
			$this->view->setScriptFile ( 'formvalidator.js' );
			$this->view->setScriptFile ( 'formvalidatorregex.js' );
			
			$this->view->setCssFile ( 'calendar/jscal2.css' );
			$this->view->setCssFile ( 'calendar/border-radius.css' );
			$this->view->setCssFile ( 'calendar/win2k.css' );
			
			$catid = $this->_request->get ( 'catid' );
			$id = $this->_request->get ( 'id' );
			
			$DB_Category = new DB_Category ();
			$DB_Category_info = $DB_Category->loadInfoByPrimary ( $catid );
			
			$DB_Copyfrom = new DB_Copyfrom ();
			$Copyfrom_list = $DB_Copyfrom->loadList ( '*', "", "listorder ASC,id DESC" );
			$this->view->assign ( 'Copyfrom_list', $Copyfrom_list );
			
			// 新闻信息
			$Model_News = new Model_News ();
			$News_Info = $Model_News->Get_News ( $id );
			
			if ($News_Info && ! empty ( $News_Info ['relation'] )) {
				$News_Info ['relation_info'] = array ();
				$relation_arr = explode ( '|', $News_Info ['relation'] );
				
				foreach ( $relation_arr as $id ) {
					$relation_info = $Model_News->Get_News ( $id );
					array_push ( $News_Info ['relation_info'], $relation_info );
				}
			}
			
			// 相关文章
			$this->view->assign ( 'catid', $catid );
			$this->view->assign ( 'id', $id );
			$this->view->assign ( 'News_Info', $News_Info );
			$this->view->assign ( 'catname', $DB_Category_info ['catname'] );
			$this->view->assign ( 'taday', date ( "Y-m-d H:i:s", time () ) );
			
			$this->render ( 'Content/manage/edit', null, true );
		}
	}
	
	/**
	 * 排序
	 */
	public function listorderAction() {
		$dosubmit = $this->_request->getPost ( 'dosubmit' );
		
		if (isset ( $dosubmit )) {
			$listorders = $this->_request->getPost ( 'listorders' );
			
			$catid = $this->_request->get ( 'catid' );
			
			if (is_array ( $listorders )) {
				$DB_News = new DB_News ();
				foreach ( $listorders as $id => $listorder ) {
					$DB_News->updateByPrimary ( array (
							'listorder' => $listorder 
					), $id );
				}
				$this->view->perRedirect ( '操作成功！', "/content/manage/list/id/{$catid}/" );
			}
			$this->view->perRedirect ( '操作失败！', "/content/manage/list/id/{$catid}/" );
		}
		
		$this->view->perRedirect ( '操作失败！', "/content/manage/list/id/{$catid}/" );
	}
	
	/**
	 * 删除新闻
	 */
	public function deleteAction() {
		$dosubmit = $this->_request->getPost ( 'dosubmit' );
		
		if (isset ( $dosubmit )) {
			$ids = $this->_request->getPost ( 'ids' );
			
			$catid = $this->_request->get ( 'catid' );
			
			if (is_array ( $ids )) {
				$Model_News = new Model_News ();
				foreach ( $ids as $id ) {
					$Model_News->delete_News ( $id );
				}
				$this->view->perRedirect ( '操作成功！', "/content/manage/list/id/{$catid}/" );
			} else {
				$this->view->perRedirect ( '请选择要删除的内容！', "/content/manage/list/id/{$catid}/" );
			}
		}
		$this->view->perRedirect ( '操作失败！', "/content/manage/list/id/{$catid}/" );
	}
	
	/**
	 * 推送到推荐位
	 */
	public function pushAction() {
		$dosubmit = $this->_request->getPost ( 'dosubmit' );
		
		if (isset ( $dosubmit )) {
			$id = $this->_request->getPost ( 'id' );
			$posid = $this->_request->getPost ( 'posid' );
		} else {
			$id = $this->_request->get ( 'id' );
			if ($id && ! empty ( $id )) {
				$DB_News = new DB_News ();
				$News_list = $DB_News->loadList ( 'id,catid,title,username', "id in($id)" );
				$this->view->assign ( 'News_list', $News_list );
			}
			
			$this->view->assign ( 'id', $id );
			$this->render ( 'Content/manage/push', null, true );
		}
	}
	
	/**
	 * 推送到其他栏目
	 */
	public function categorylistAction() {
		$dosubmit = $this->_request->getPost ( 'dosubmit' );
		
		if (isset ( $dosubmit )) {
			$id = $this->_request->getPost ( 'id' );
			$catid = $this->_request->getPost ( 'catid' );
			
			$DB_News = new DB_News ();
		
		} else {
			$id = $this->_request->get ( 'id' );
			if ($id && ! empty ( $id )) {
				$DB_News = new DB_News ();
				$News_list = $DB_News->loadList ( 'id,catid,title,username', "id in($id)" );
				$this->view->assign ( 'News_list', $News_list );
			}
			
			$DB_Category = new DB_Category ();
			$categorys = $DB_Category->loadList ( '*', "", "listorder ASC,id ASC" );
			
			$this->view->assign ( 'categorys', $categorys );
			$this->view->assign ( 'id', $id );
			
			$this->render ( 'Content/manage/categorylist', null, true );
		}
	}
	
	/**
	 * 批量移动
	 */
	public function removeAction() {
		$id = $this->_request->get ( 'id' );
		if ($id && ! empty ( $id )) {
			$DB_News = new DB_News ();
			$News_list = $DB_News->loadList ( 'id,catid,title,username', "id in($id)" );
			$this->view->assign ( 'News_list', $News_list );
		}
		
		$DB_Category = new DB_Category ();
		$categorys = $DB_Category->loadList ( '*', "", "listorder ASC,id ASC" );
		
		$this->view->assign ( 'categorys', $categorys );
		$this->view->assign ( 'id', $id );
		$this->render ( 'Content/manage/remove', null, true );
	}
	
	/**
	 * 搜索内容
	 */
	public function searchAction() {
		
		$this->view->setScriptFile ( 'admin/admin_common.js' );
		$this->view->setScriptFile ( 'cookie.js' );
		
		$this->view->setScriptFile ( 'admin/calendar/calendar.js' );
		$this->view->setScriptFile ( 'admin/calendar/lang/en.js' );
		
		$this->view->setCssFile ( 'calendar/jscal2.css' );
		$this->view->setCssFile ( 'calendar/border-radius.css' );
		$this->view->setCssFile ( 'calendar/win2k.css' );
		
		$dosearch = $this->_request->getPost ( 'dosearch' );
		$catid = $this->_request->getPost ( 'catid' );
		$start_time = $this->_request->getPost ( 'start_time' );
		$end_time = $this->_request->getPost ( 'end_time' );
		$posids = $this->_request->getPost ( 'posids' );
		$searchtype = $this->_request->getPost ( 'searchtype' );
		$keyword = $this->_request->getPost ( 'keyword' );
		
		$this->view->assign ( 'id', $catid );
		
		$DB_News = new DB_News ();
		$where = " 1=1 ";
		if (! empty ( $catid )) {
			$where .= " and catid={$catid}";
		}
		if (! empty ( $start_time )) {
			$start_time = strtotime ( $start_time . ' 00:00:00' );
			$where .= " and createtime >={$start_time}";
		}
		if (! empty ( $end_time )) {
			$end_time = strtotime ( $end_time . ' 23:59:59' );
			$where .= " and createtime >={$end_time}";
		}
		
		if (! empty ( $posids )) {
		
		}
		
		if (! empty ( $keyword )) {
			if ($searchtype == 1) {
				$where .= " and title like '%{$keyword}%'"; // 标题
			}
			if ($searchtype == 2) {
				$where .= " and description like '%{$keyword}%'"; // 简介
			}
			if ($searchtype == 3) {
				$where .= " and username = '%{$keyword}%'"; // 用户名
			}
			if ($searchtype == 4) {
				$where .= " and id ={$keyword}"; // ID
			}
		}
		
		$Page = new Cms_Pager ( $DB_News );
		
		// 设置Ajax分页
		// $Page = new Cms_Pager ( $DB_News, 'page', 'ajax' );
		// $Page->setAjaxFun ('ContentPage',"/content/manage/ajaxlist/id/{$id}/"
		// );
		
		$Pagelimit = $Page->loadPagerData ( 10, $where );
		
		$News_list = $DB_News->loadList ( '*', $where, null, $Pagelimit );
		
		if ($News_list) {
			foreach ( $News_list as $key => $val ) {
				if ($val ['style']) {
					$style = explode ( ';', $val ['style'] );
					$News_list [$key] ['style'] = '';
					if (! empty ( $style [0] ) && strstr ( $style [0], '#' )) {
						$News_list [$key] ['style'] .= "color:{$style[0]};";
					}
					if (! empty ( $style [0] ) && strstr ( $style [0], 'bold' )) {
						$News_list [$key] ['style'] .= "font-weight:{$style[0]};";
					}
					if (! empty ( $style [1] ) && strstr ( $style [1], '#' )) {
						$News_list [$key] ['style'] .= "color:{$style[1]};";
					}
					if (! empty ( $style [1] ) && strstr ( $style [1], 'bold' )) {
						$News_list [$key] ['style'] .= "font-weight:{$style[1]};";
					}
				}
				$News_list [$key] ['updatetime'] = date ( "Y-m-d H:i:s", $val ['updatetime'] );
			}
		}
		
		$this->view->assign ( "pageBlock", $Page->loadPagerTpl () );
		$this->view->assign ( 'News_list', $News_list );
		$this->render ( 'Content/manage/list', null, true );
	}
	
	/**
	 * 左侧菜单
	 */
	public function categorysAction() {
		$this->view->setCssFile ( 'jquery.treeview.css' );
		$this->view->setScriptFile ( 'jquery.cookie.js' );
		$this->view->setScriptFile ( '/admin/jquery.treeview.js' );
		$this->view->setScriptFile ( '/admin/jquery.treeview.async.js' );
		
		$DB_Category = new DB_Category ();
		$categorys = $DB_Category->loadList ( '*', "", "listorder ASC,id ASC" );
		
		// 这块配置子菜单是否ajax取的
		$ajax_show = 0; // 0:为默认加载输出 1:为AJAX动态加载输出
		
		$tree = new Cms_Tree ();
		
		$config = Zend_Registry::get ( 'config' );
		foreach ( $categorys as $key => $val ) {
			$categorys [$key] ['add_icon'] = " <a href=\"/content/manage/list/id/{$val['id']}/\" target=\"right\"><img alt=\"添加\" src=\"{$config->view_conf->siteImgPath}/add_content.gif\"></a> ";
		}
		
		$tree->init ( $categorys );
		
		$strs = "<span class='\$icon_type'>\$add_icon<a href='/content/manage/list/id/\$id/' target='right' onclick='open_list(this)'>\$catname</a></span>";
		$strs2 = "<span class='folder'>\$catname</span>";
		
		$categorys = $tree->get_treeview ( 0, 'category_tree', $strs, $strs2, $ajax_show );
		
		$this->view->assign ( 'ajax_show', $ajax_show );
		$this->view->assign ( 'categorys', $categorys );
		
		$this->render ( 'Content/manage/categorys', null, true );
	}
	
	/**
	 * AJAX方式取子节点
	 */
	public function menuAction() {
		$id = $this->_request->getPost ( 'root' );
		$modelid = $this->_request->getPost ( 'modelid' );
		
		$DB_Category = new DB_Category ();
		$categorys = $DB_Category->loadList ( '*', "", "listorder ASC,id ASC" );
		
		$tree = new Cms_Tree ();
		
		$config = Zend_Registry::get ( 'config' );
		foreach ( $categorys as $key => $val ) {
			$categorys [$key] ['add_icon'] = " <a href=\"/content/manage/list/id/{$val['id']}/\" target=\"right\"><img alt=\"添加\" src=\"{$config->view_conf->siteImgPath}/add_content.gif\"></a> ";
		}
		$tree->init ( $categorys );
		$strs = "<span class='\$icon_type'>\$add_icon<a href='/content/manage/list/id/\$id/' target='right' onclick='open_list(this)'>\$catname</a></span>";
		
		$data = $tree->creat_sub_json ( $id, $strs );
		echo $data;
		exit ();
	}
	
	/**
	 * 取关键字
	 */
	public function getkeywordsAction() {
		$title = $this->_request->getPost ( 'title' );
		echo '测试';
		exit ();
	}
	
	/**
	 * 检查标题是否存在
	 */
	public function checktitleAction() {
		$catid = $this->_request->getPost ( 'catid' );
		$title = $this->_request->getPost ( 'title' );
		if (empty ( $catid ) || empty ( $title )) {
			echo - 1;
			exit ();
		}
		$DB_News = new DB_News ();
		$DB_News_Info = $DB_News->loadInfo ( 'title', "title='{$title}'" );
		if ($DB_News_Info) {
			echo 1;
			exit ();
		} else {
			echo 0;
			exit ();
		}
	}
	
	/**
	 * 添加相关文章
	 */
	public function relationlistAction() {
		$modelid = $this->_request->get ( 'modelid' );
		
		if (! isset ( $modelid )) {
			$this->view->assign ( 'message', "参数错误!" );
		} else {
			$DB_News = new DB_News ();
			$DB_Category = new DB_Category ();
			$Category_Info = $DB_Category->loadInfoByPrimary ( $modelid );
			$Category_List = $DB_Category->loadList ( "*", "parentid != 0" );
			
			$where = " 1=1 ";
			if (! empty ( $modelid )) {
				$where .= " and catid={$modelid}";
			}
			
			if ($_GET ['catid']) {
				$catid = intval ( $_GET ['catid'] );
				$where .= "catid='$catid'";
			}
			
			if (isset ( $_GET ['keywords'] )) {
				$keywords = trim ( $_GET ['keywords'] );
				$field = $_GET ['field'];
				if (in_array ( $field, array (
						'id',
						'title',
						'keywords',
						'description' 
				) )) {
					if ($field == 'id') {
						$where .= " AND `id` ='$keywords'";
					} else {
						$where .= " AND `$field` like '%$keywords%'";
					}
				}
			}
			
			$Page = new Cms_Pager ( $DB_News );
			$where .= " AND status=1 ";
			$Pagelimit = $Page->loadPagerData ( 10, $where );
			$News_list = $DB_News->loadList ( '*', $where, null, $Pagelimit );
			if ($News_list) {
				foreach ( $News_list as $key => $val ) {
					if ($val ['style']) {
						$style = explode ( ';', $val ['style'] );
						$News_list [$key] ['style'] = '';
						if (! empty ( $style [0] ) && strstr ( $style [0], '#' )) {
							$News_list [$key] ['style'] .= "color:{$style[0]};";
						}
						if (! empty ( $style [0] ) && strstr ( $style [0], 'bold' )) {
							$News_list [$key] ['style'] .= "font-weight:{$style[0]};";
						}
						if (! empty ( $style [1] ) && strstr ( $style [1], '#' )) {
							$News_list [$key] ['style'] .= "color:{$style[1]};";
						}
						if (! empty ( $style [1] ) && strstr ( $style [1], 'bold' )) {
							$News_list [$key] ['style'] .= "font-weight:{$style[1]};";
						}
					}
					$News_list [$key] ['createtime'] = date ( "Y-m-d", $val ['createtime'] );
					$News_list [$key] ['updatetime'] = date ( "Y-m-d", $val ['updatetime'] );
				}
			}
			
			$this->view->assign ( 'Category_Info', $Category_Info );
			$this->view->assign ( 'Category_List', $Category_List );
			$this->view->assign ( "pageBlock", $Page->loadPagerTpl () );
			$this->view->assign ( 'News_list', $News_list );
		}
		$this->render ( 'Content/manage/relationlist', null, true );
	}
}
?>